package com.maiworld.seller.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.maiworld.mapper.TbOrderMapper;
import com.maiworld.pojo.TbOrder;
import com.maiworld.seller.service.OrderService;

import entity.PageResult;
@Service
public class OrderServiceImpl implements OrderService {

	@Autowired
	private TbOrderMapper tbOrderMapper;

	//完成预定义订单信息 
	@Override
	public Map<String, Object> add(Map<String, String> params) {
		
		Map<String, Object> result = new HashMap<String,Object>();
		
		TbOrder order = new TbOrder();
		order.setSid(Long.parseLong(params.get("sid")));
		order.setNewsId(Long.parseLong(params.get("newsId")));
		order.setUsername(params.get("username"));
		order.setPhone(params.get("phone"));
		order.setCard(params.get("card"));
		order.setRecommend(params.get("recommend"));
		order.setSignurl(params.get("signurl"));
		order.setStatus(params.get("status"));
		order.setPaymentStatus("0");
		tbOrderMapper.insertSelective(order);
		
		result.put("order_id", order.getId());
		result.put("statusCode", 200);
		result.put("message", "下单成功");		
		return result;
	}

	@Override
	public TbOrder selectByPrimaryKey(Long id) {
		// TODO Auto-generated method stub
		return tbOrderMapper.selectByPrimaryKey(id);
	}

	@Override
	public PageResult selectByOrder(TbOrder order, int pageNum, int pageSize) {
		
		PageHelper.startPage(pageNum, pageSize);
		Page<Map<String, Object>> page = (Page<Map<String, Object>>) tbOrderMapper.selectByOrder(order);
		return new PageResult(page.getTotal(), page.getResult());
	}
}
		
